<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>工程师注册页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">

    <!---->
    <div class="layui-row">
        <form class="layui-form" method="post" enctype="multipart/form-data">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name"
                           lay-verify="name" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux" id="msg">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="openid">微信openid</label>
                <div class="layui-input-inline">
                    <input type="text" id="openid" name="openid"
                           lay-verify="name" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="tel">手机号</label>
                <div class="layui-input-inline">
                    <input type="text" id="tel" name="tel"
                           lay-verify="rejectMsg" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="yzm" class="layui-form-label"> <span
                        class="x-red"></span>验证码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="yzm" name="yzm"
                           lay-verify="unitid" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="goodat" class="layui-form-label"> <span
                        class="x-red"></span>擅长
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="goodat" name="goodat"
                           lay-verify="unitid" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"> <span
                        class="x-red"></span>个人头像
                </label>
                <div class="layui-input-inline">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test1">选择文件</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo1" width="150px" height="150px">
                        </div>
                    </div>
                    <input type="hidden" id="person_pic" name="person_pic"
                           lay-verify="person_pic" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"> <span
                        class="x-red"></span>身份证正面
                </label>
                <div class="layui-input-inline">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test3">选择文件</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo3" width="200px" height="150px">
                            <p id="demoText"></p>
                        </div>
                    </div>
                    <input type="hidden" id="id_zheng" name="id_zheng"
                           lay-verify="id_zheng" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"> <span
                        class="x-red"></span>身份证反面
                </label>
                <div class="layui-input-inline">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test2">选择文件</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo2" width="200px" height="150px">
                        </div>
                    </div>
                    <input type="hidden" id="id_fan" name="id_fan"
                           lay-verify="id_fan" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <div class="layui-input-inline">
                    <div class="layui-upload">
                    </div>
                    <button class="layui-btn" lay-filter="add" lay-submit="" id="add">注册</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer', 'jquery', 'upload'], function () {
    $ = layui.jquery;
    var form = layui.form,
        layer = layui.layer,
        upload = layui.upload;
    //上传个人头像
    upload.render({
        elem: '#test1'
        , url: 'upload'       //上传路径
        /*, auto: false       //关闭自动上传
        , bindAction: '#test11'*/
        , accept: 'images'        //只允许上传图片
        , choose: function (obj) {                 //选择文件后的回调函数
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo1').prop('src', result); //图片链接（base64）
            });
        }
        , done: function (res) {
            console.log(JSON.stringify(res));
            $("#person_pic").prop("value", res.msg);
            form.render();
        }
    });

    //上传身份证反面
    upload.render({
        elem: '#test2'
        , url: 'upload'       //上传路径
        /*, auto: false       //关闭自动上传
        , bindAction: '#test22'*/
        , accept: 'images'        //只允许上传图片
        , choose: function (obj) {                 //选择文件后的回调函数
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo2').prop('src', result); //图片链接（base64）
            });
        }
        , done: function (res) {
            $("#id_fan").prop("value", res.msg);
            form.render();
        }
    });

    //上传身份证正面
    upload.render({
        elem: '#test3'
        , url: 'upload'       //上传路径
        /* , auto: false       //关闭自动上传
         , bindAction: '#test33'*/
        , accept: 'images'        //只允许上传图片
        , choose: function (obj) {                 //选择文件后的回调函数
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo3').prop('src', result); //图片链接（base64）
            });
        }
        , done: function (res) {
            console.log(res)
            $("#id_zheng").prop("value", res.msg);
            form.render();
        }
    });

    var flag = false;
    $("#name").change(function () {
        var value = $(this).val();
        console.log(value);
        $.get("VerifyName", {name: value}, function (p) {
            if (p.code == 0) {
                flag = true;
                $("#msg").html("<span style='color: green'>名称可以使用</span>");
            } else {
                flag = false;
                $("#msg").html("<span style='color:red'>登录名重复</span>")
            }
        })
    })


    //监听提交
    form.on('submit(add)',
        function (d) {
            if (flag == false) {
                layer.msg("用户名重复,请更换登录名");
                return false;
            }
            alert(JSON.stringify(d.field));
            $.get("repairmanAdd", d.field, function (data) {
                if (data.code == 0) {
                    layer.msg("注册成功",{icon:6},function () {
                        location.href="repairman_login.html";
                    });

                } else {
                    layer.msg(data.msg, {icon: 5});
                }
            })
            return false;
        });
});
</script>
</div>

</body>

</html>
